package com.zret.oasys.operation.dept;
/**
 * operation接口下，添加员工方法
 */
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.zret.oasys.entity.Dept;

public class AddDept implements DeptServletOperation 
{
	@Override
	public void doOperation(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		//添加部门Servlet op 判断addDept
		//设置json编码
		response.setContentType("application/json;charset=utf-8");
		
		//获取部门id的值
		int deptid = Integer.valueOf(request.getParameter("deptid"));
		//获取部门经理id的值
		int managerid = Integer.valueOf(request.getParameter("managerid"));
		//获取部门名称的值
		String deptname = request.getParameter("deptname");
		
		//创建部门类对象
		Dept dept = new Dept(deptid, managerid, deptname);
		//调用deptservice的addDept方法 (boolean 类型)
		boolean flag = deptservice.addDepts(dept);
		//控制台输出结果flag
		System.out.println(flag);
		
		//页面ajxa输出
		PrintWriter out = response.getWriter();
		
		Gson gson = new Gson();
		String msg1 = gson.toJson("添加部门成功");
		String msg2 = gson.toJson("添加部门失败");
		if (flag)
		{
			out.print(msg1);
		}
		else
		{
			out.print(msg2);
		}
	}

}
